<?php

namespace App\Http\Controllers;


use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Services\ConfigServices;
use App\Http\Services\LightsCardServices;
use Illuminate\Http\Request;


//点亮卡活动
class LightsCardController extends Controller
{
    private $lights_card_services;
    private $config_services;


    public function __construct()
    {
        $this->lights_card_services = new LightsCardServices();
        $this->config_services = new ConfigServices();
    }

    //购买点亮卡
    public function payCard(Request $request)
    {
        $this->checkDate();
        $user_id = $request->input('user_id', 0);
        $num = $request->input('num', 0);
        $res = $this->lights_card_services->payLightsCard($user_id, $num);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

    //获取奖品记录
    public function getAwardLog(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        $res = $this->lights_card_services->awardLog($user_id);
        OutJson::toJson(0, '成功', $res);
    }

    //获取用户相关信息
    public function getInfo(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        $res = $this->lights_card_services->getInfo($user_id);
        OutJson::toJson(0, '成功', $res);
    }

    //获取点亮礼物列表
    public function getGiftList(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        $res = $this->lights_card_services->getGift($user_id);
        OutJson::toJson(0, '成功', $res);
    }

    //点亮礼物
    public function lightsGift(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        $gift_id = $request->input('gift_id', 0);
        $res = $this->lights_card_services->lightsGift($user_id, $gift_id);
        OutJson::toJson($res['code'], $res['msg'], []);
    }

    //赠送勋章
    public function getMedal(Request $request)
    {
        $this->checkDate();
        $user_id = $request->input('user_id', 0);
        $res = $this->lights_card_services->getMedal($user_id);
        OutJson::toJson($res['code'], $res['msg'], []);
    }

    public function getPond(Request $request)
    {
        $num = $request->input('num', 0);
        $del = $request->input('del', 0);

        $this->lights_card_services->prop($num,$del);

    }

    public function checkDate()
    {
        $check_date = $this->config_services->checkConfigDate(27, time(), 'card_date');
        if (!$check_date) {
            write_log('dishTimeOut', 'timeError', []);
            OutJson::toJson(3001, '活动时间错误', []);
        }
    }

}